<template>
  <header>
    <div class="box">
      <h1>云慧学习社区</h1>
      <ul>
        <li>
          <router-link to="/home">首页</router-link>
        </li>
        <!-- <li>
          <router-link to="/login">登录</router-link>
        </li> -->
        <li>
          <router-link to="/sign">签到</router-link>
        </li>
        <li>
          <router-link to="/blog">博客</router-link>
        </li>
        <li>
          <router-link to="/my-class">我的课程</router-link>
        </li>
        <!-- <li>
          <router-link to="/visualization">可视化</router-link>
        </li> -->
        <li>
          <router-link to="/robot">云慧问答</router-link>
        </li>
        <li class="person-item">
          <router-link to="/person" class="person-link">
            <span>个人中心</span>
          </router-link>
        </li>
        <li class="avatar-item">
          <img class="avatar" src="@/assets/china.png" alt="头像" @click="handleAvatarClick" />
          <input
            type="file"
            ref="fileInput"
            style="display: none"
            accept="image/*"
            @change="handleFileChange"
          />
        </li>
      </ul>
    </div>
  </header>
</template>

<style scoped>
header {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 70px;
  background: linear-gradient(to right, rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.5));
  backdrop-filter: blur(15px);
  color: white;
  z-index: 1999;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

header div {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 40px;
  height: 100%;
}

h1 {
  font-size: 26px;
  font-weight: 600;
  color: white;
  margin: 0;
  letter-spacing: 1px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

ul {
  display: flex;
  gap: 35px;
  margin: 0;
  padding: 0;
  list-style: none;
  align-items: center;
}

li {
  font-size: 16px;
  position: relative;
  padding: 0 5px;
  display: flex;
  align-items: center;
}

li a {
  color: rgba(255, 255, 255, 0.9);
  text-decoration: none;
  transition: all 0.3s ease;
  position: relative;
  padding: 5px 0;
  font-weight: 500;
}

li a::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 0;
  height: 2px;
  background-color: #fff;
  transition: all 0.3s ease;
  transform: translateX(-50%);
}

li a:hover {
  color: #fff;
  transform: translateY(-2px);
}

li a:hover::after {
  width: 100%;
}

.router-link-active {
  color: #fff;
  font-weight: 600;
}

.router-link-active::after {
  width: 100%;
}

.person-item {
  display: flex;
  align-items: center;
}

.person-link {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar-item {
  display: flex;
  align-items: center;
  cursor: pointer;
  margin-left: 10px;
}

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.8);
  object-fit: cover;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.avatar:hover {
  transform: scale(1.1);
  border-color: #fff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}
</style>

<script>
export default {
  name: 'topNavIndex',
  methods: {
    handleAvatarClick() {
      this.$refs.fileInput.click();
    },
    handleFileChange(event) {
      const file = event.target.files[0];
      if (file) {
        // 这里可以添加文件类型和大小的验证
        const reader = new FileReader();
        reader.onload = (e) => {
          // 更新头像预览
          this.$el.querySelector('.avatar').src = e.target.result;
          // 这里可以添加上传头像到服务器的逻辑
        };
        reader.readAsDataURL(file);
      }
    }
  }
}
</script>

